package org.pezke.akunature.model.fb;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

import org.hibernate.search.annotations.Indexed;
import org.pezke.akunature.model.BaseObject;

/**
 * @author igarcia
 */
@Entity
@Table(name = "akn_fb_")
@Indexed
@XmlRootElement
public class FBach extends BaseObject implements Serializable {

	/** serial version UID */
	private static final long serialVersionUID = 1L;

	/***************************************************************************
	 * Atributos
	 **************************************************************************/

	/** Identificador */
	private Long id = null;

	/** Nombre del fb */
	private String name = null;
	private String nameEng = null;
	private String nameLat = null;

	/** Resto de parametros */
	private String sample = null;
	private String description = null;

	/** Grupo */
	FBachGroup group = null;
	
	/** Claves */
	Set<FBachKey> keys = null;
	
	/** Consideraciones */
	Set<FBachConsideration> considerations = null;
	

	/***************************************************************************
	 * Constructores
	 **************************************************************************/

	/**
	 * 
	 * <b>Constructor:</b> FBach
	 */
	public FBach() {

	}

	/***************************************************************************
	 * Getters y setters
	 **************************************************************************/

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id_")
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "name_")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "name_eng_")
	public String getNameEng() {
		return nameEng;
	}

	public void setNameEng(String nameEng) {
		this.nameEng = nameEng;
	}

	@Column(name = "name_lat_")
	public String getNameLat() {
		return nameLat;
	}

	public void setNameLat(String nameLat) {
		this.nameLat = nameLat;
	}

	@Column(name = "sample_")
	public String getSample() {
		return sample;
	}

	public void setSample(String sample) {
		this.sample = sample;
	}

	@Column(name = "description_")
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@ManyToOne
	@JoinColumn(name = "group_id_")
	public FBachGroup getGroup() {
		return group;
	}

	public void setGroup(FBachGroup group) {
		this.group = group;
	}

	@ManyToMany
	@JoinTable(name = "akn_fb_rel_key_", 
		joinColumns = @JoinColumn(name = "fb_id_"), 
		inverseJoinColumns = @JoinColumn(name = "key_id_"))
	public Set<FBachKey> getKeys() {
		return keys;
	}

	public void setKeys(Set<FBachKey> keys) {
		this.keys = keys;
	}

	@ManyToMany
	@JoinTable(name = "akn_fb_rel_cons_", 
		joinColumns = @JoinColumn(name = "fb_id_"), 
		inverseJoinColumns = @JoinColumn(name = "consideration_id_"))
	public Set<FBachConsideration> getConsiderations() {
		return considerations;
	}

	public void setConsiderations(Set<FBachConsideration> considerations) {
		this.considerations = considerations;
	}
	
	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object obj) {
		FBach other = (FBach)obj;
		return other.getId().longValue()==other.getId().longValue();
	}

	/*
	 * (non-Javadoc)
	 * @see org.pezke.akunature.model.BaseObject#toString()
	 */
	public String toString() {
		StringBuffer result = new StringBuffer("FBach [id=");
		result.append(this.id);
		result.append("]");
		return result.toString();
	}

	/*
	 * (non-Javadoc)
	 * @see org.pezke.akunature.model.BaseObject#hashCode()
	 */
	public int hashCode() {
		long f = this.id.longValue();
		return (int) (f ^ (f >>> 32));
	}

}
